﻿
@{
    ViewBag.Title = "AddArrange";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<script>
    var keyvalue = $.request("keyvalue");
    $(function () {
        init();
        if (!!keyvalue) {
            $.ajax({
                url: "/TherapeutistManage/TherapeutistCompleteList/GetFormJson?r=" + Math.random(),
                data: { keyvalue: keyvalue },
                dataType: "json",
                async: false,
                success: function (data) {
                    $("#form1").formSerialize(data);
                }
            });
            $("#ysgh").attr("disabled", "disabled").css("background-color", "#f1f4f6");
            $("#Name").attr("disabled", "disabled").css("background-color", "#f1f4f6");
        }
    })

    function init() {
        var date = new Date;
        //年份
        $("#year").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.yearArr && top.clients.yearArr.length) {
                    $.each(top.clients.yearArr, function () {
                        resultObjArr.push({ id: this, text: this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: 1900 + date.getYear(),
        });
        //月份
        $("#month").newtouchBindSelect({
            datasource: function () {
                var resultObjArr = new Array();
                if (top.clients.monthArr && top.clients.monthArr.length) {
                    $.each(top.clients.monthArr, function () {
                        resultObjArr.push({ id: this, text: parseInt(this) < 10 ? "0" + this : this });
                    });
                }
                return resultObjArr;
            },
            selectedValue: date.getMonth() + 1,
        });
    }

    function submitForm() {
        if (checkNotNull()) {
            $.submitForm({
                url: "/TherapeutistManage/TherapeutistCompleteList/EditRehabDoctorRange?keyvalue=" + keyvalue,
                param: $("#form1").formSerialize(),
                success: function () {
                    $.currentWindow().$("#HisgridList").resetSelection();
                    $.currentWindow().$("#HisgridList").trigger("reloadGrid");
                    $.loading(false);
                }
            })
        }
    }

    function checkNotNull() {
        var validator = $('#form1').validate();
        validator.settings = {
            rules: {
                ysgh: { required: true },
                //Name: { required: true },
                year: { required: true },
                month: { required: true },
                ts: { required: true }
            },
            messages: {
                ysgh: { required: "工号不能为空" },
                //Name: { required: "名字不能为空" },
                year: { required: "年份不能为空" },
                month: { required: "月份不能为空" },
                ts: { required: "天数不能为空" }
            },
            showErrors: function (errorMap, errorList) {
                if (!$.isEmptyObject(errorList)) {
                    if (Array.isArray(errorList) && errorList.length == 0) {
                        return;
                    }
                    $.modalAlert(errorList[0].message, 'warning');
                }
            }
        }
        if (!validator.form()) {
            return false;
        }
        if (!((/^(\+|-)?\d+$/).test($("#ts").val())) || ($("#ts").val() < 1)) {
            $.modalAlert("天数不是大于0的整数，请确认。", 'warning');
            return;
        }
        if (($("#ts").val() > 31)) {
            $.modalAlert("不能大于31天，请确认。", 'warning');
            return;
        }
        return true;
    }
</script>
<form id="form1">
    <div style="padding-right:30px">
        <table class="form">
            <tr>
                <td class="formTitle"><span style="color:red">*</span>工号：</td>
                <td class="formValue">
                    <input type="text" id="ysgh" name="ysgh" class="form-control" />
                    <input type="hidden" id="Id" class="form-control" />
                </td>
            </tr>
            <tr>
                <td class="formTitle">姓名：</td>
                <td class="formValue">
                    <input type="text" id="Name" name="Name" class="form-control" />
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span style="color:red">*</span>年份：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="year" name="year" class="form-control">
                        <option value="">===请选择===</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span style="color:red">*</span>月份：</td>
                <td class="formValue formDdlSelectorTd">
                    <select id="month" name="month" class="form-control">
                        <option value="">===请选择===</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="formTitle"><span style="color:red">*</span>天数：</td>
                <td class="formValue">
                    <input type="text" id="ts" name="ts" class="form-control" />
                </td>
            </tr>

        </table>
    </div>

</form>

